package com.weipai;
import hprose.server.HproseTcpServer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;

import java.util.Date;

import static com.weipai.ShutdownHook.addShutdownHook;

/**
 * Created by Administrator on 2017/11/19 0019.
 */
public class ServerTcp {
        public static String hello(String name) {
            return "Hello " + name + "!";
        }
    public static String broker_url = "47.97.4.127:9876";
    public static DefaultMQProducer producer ;

    public static  boolean generatemessage(){

        return Boolean.TRUE;
    }
    public static class TaskTHREAD extends Thread {
        @Override
        public void run() {
            System.out.println("thread end\n\n");
        }
    }


        public static void main(String[] args) throws Exception {
            long ctime = new Date().getTime();

             producer = new DefaultMQProducer("fffff");


            producer.setNamesrvAddr(broker_url);
            producer.start();
            producer.setRetryTimesWhenSendAsyncFailed(0);
            HproseTcpServer server = new HproseTcpServer("tcp://0.0.0.0:4321");
            server.add("hello", ServerTcp.class);
            //ramq消息队列公共函数
            server.add("generateTask", Index.class);
            //rocketmq消息队列公共函数
            server.add("generatemessage", ServerTcp.class);
            server.add("GenerateMessage", RocketmqGenerateTask.class);


            final TaskTHREAD taskThread = new TaskTHREAD();
            addShutdownHook(taskThread,producer);
            server.start();
          //  producer.shutdown();
            System.out.println("START");

          //  System.in.read();
          //  server.stop();
           // System.out.println("STOP");
            /**
             * 应用退出时，要调用shutdown来清理资源，关闭网络连接，从MetaQ服务器上注销自己
             * 注意：我们建议应用在JBOSS、Tomcat等容器的退出钩子里调用shutdown方法
             */
        }
}
